package com.pro.service.imple;

import com.pro.dao.CourseRecordMapper;
import com.pro.entity.CoursePlus;
import com.pro.entity.CourseRecord;
import com.pro.entity.JsMicrocirclePlus;
import com.pro.entity.ProductPlus;
import com.pro.service.CourseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author 笑笑
 * @create 2021/11/4下午 03:59
 */
@Service
public class CourseRecordServiceImple implements CourseRecordService {

    @Autowired
    private CourseRecordMapper courseRecordMapper;

    @Override
    //查询所有商品或视频的审核记录
    public List<ProductPlus> getAllCourseRecord(ProductPlus productPlus){
        return courseRecordMapper.getAllCourseRecord(productPlus);
    }

    //审批操作
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateCourseRecord(CourseRecord courseRecord) throws Exception {
        courseRecord.setImplementDate(new Date());
        if (courseRecord.getId() == null || courseRecord.getId() < 1){
            throw new Exception("请重新操作");
        }
        return courseRecordMapper.updateCourseRecord(courseRecord);
    }

    //查询所有课程的审核记录
    @Override
    public List<CoursePlus> getAllCourse(CoursePlus coursePlus) {
        return courseRecordMapper.getAllCourse(coursePlus);
    }

    //查询所有微圈的审核记录
    @Override
    public List<JsMicrocirclePlus> getAllMicroCircle(JsMicrocirclePlus jsMicrocirclePlus) {
        return courseRecordMapper.getAllMicroCircle(jsMicrocirclePlus);
    }

    //根据微圈id查询信息
    @Override
    public JsMicrocirclePlus getById(Integer microcircleId) throws Exception {
        if (microcircleId == null || microcircleId < 1){
            throw new Exception("id不正确");
        }
        return courseRecordMapper.getById(microcircleId);
    }
}
